package so.go4.controller;

import com.alibaba.fastjson.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by SQB on 2015/5/30.
 */
@Controller
@RequestMapping("/angular")
public class AngularJS {
    private static Logger logger = Logger.getLogger(AngularJS.class);

    @RequestMapping("/test")
    //@RequestBody将前台传来的JSON转成JSONObject,后台用jsonObject.getString直接可以获取
    public void testAngular(@RequestBody JSONObject jsonObject,HttpServletRequest request,HttpServletResponse response){
        String superhero = jsonObject.getString("email");
        System.out.println(superhero+"------this is email");
        System.out.println(jsonObject);
        try {
            PrintWriter pw = response.getWriter();
            response.setContentType("application/json;charset=utf-8");
            logger.info("{\"email\":\"409747494@qq.com\",\"password\":\"sqb123123\",\"password_confirm\":\"sqb123123\",\"radio\":\"option1\",\"username\":\"409747494@qq.com\"}");
            pw.print("{\"email\":\"309747494@qq.com\",\"password\":\"sqb123123\",\"password_confirm\":\"sqb123123\",\"radio\":\"option1\",\"username\":\"409747494@qq.com\"}");
            pw.flush();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
